<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>客服管理</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../assets/style/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../assets/layui/layui.js"></script>
    <script src="../assets/js/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            添加客服
                        </div>
                        <div class="layui-card-body">
                            <form class="layui-form" action="">
                                <input type="hidden" name="id" value="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="请输入用户名" class="layui-input" value="">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">密码</label>
                                    <div class="layui-input-inline">
                                        <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="请输入密码" class="layui-input" value="">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">备注</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="remark" autocomplete="off" class="layui-input" value="">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">状态</label>
                                    <div class="layui-input-inline">
                                        <input type="radio" name="status" value="1" title="启用" checked>
                                        <input type="radio" name="status" value="0" title="禁用" >
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a class="layui-btn" lay-submit lay-filter="formSubmit" id="submitBtn">提交</a>
                                        <a class="layui-btn layui-btn-primary" href="index.html">取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form'], function(){
            var $ = layui.$
                ,form = layui.form;

            form.verify({
                username: function(value){
                    if (value.length < 4 || value.length > 16) {
                        return '请输入用户名，4到16个字符';
                    }
                }
                , password: function (value) {
                    if (value.length < 6 || value.length > 16) {
                        return '请输入密码，6到16个字符';
                    }
                }
            });

            //监听提交
            form.on('submit(formSubmit)', function(data){
                if (data.field.password) {
                    data.field.password = hex_md5(data.field.password.trim());
                }
                layer.msg('提交中', {
                    shadeClose: false
                    ,icon: 16
                    ,shade: 0.01
                });
                $('#submitBtn').addClass('layui-btn-disabled');
                $.ajax({
                    type: "POST",
                    url: "/cs_user/save",
                    data: data.field,
                    success:function(response){
                        var dataObj=$.parseJSON(response);
                        if (dataObj.code===0) {
                            layer.msg('数据提交成功', {icon: 6});
                            setTimeout(function(){
                                location.href = '/cs_user/index';
                            }, 1000);
                        } else {
                            layer.msg(dataObj.msg, {icon: 5});
                            $('#submitBtn').removeClass('layui-btn-disabled');
                        }
                    },
                    error: function (request, status, error) {
                        layer.msg('哦噢，网络开小差了', {icon: 5});
                        $('#submitBtn').removeClass('layui-btn-disabled');
                    }
                });
                return false;
            });
        });
    </script>
</div>
</body>
</html>
